import Request from './request';
import { BASE_URL, API_BASE_URL, SERIAL, IS_DEV, ACCEPT_PLATFORM } from '../config.js';
const http = new Request();
http.setConfig((config) => {
  config.baseUrl = BASE_URL;
  // config.baseUrl = API_BASE_URL;
  return config
})
let userType = '1';
// #ifdef MP-TOUTIAO
userType = '1';
// #endif
// #ifdef MP-WEIXIN
userType = '4';
// #endif
// #ifdef MP-ALIPAY
userType = '5';
// #endif

http.interceptor.request((config, cancel) => {
  config.header = {
    ...config.header,
    'api-token': global.token || '',
		// 'api-token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6ImtleUlkIn0.eyJ1c2VySWQiOjMsInVzZXJPcGVuSWQiOiJfMDAwVG1XcUZ1YVRKMDBYZjhjNmpEZHB4RXc0LXAwME1TNDAiLCJwaG9uZSI6IjE4MDM3MzMzNTYzIiwidHlwZSI6MSwic3RvcmVfaWQiOjB9.c-0uIqwC8Y5zaEwvEDRRpzx7dN7bo6-k7jQOcJkwBB8',
	'user-type': userType,
    'Accept-Language': global.locale,
    'Accept-Platform': ACCEPT_PLATFORM,
    'Accept-Serial': SERIAL,
    //CUSTOM_HEADER
  }
  if (IS_DEV == 2) {
    config.data = {
      ...config.data,
      ismock: 0,
    }
  }
  return config;
})

http.interceptor.response((response) => {
  return response;
})

export {
  http
};
